<cfquery name="exitSurveys" datasource="wms">
	select Student_ID, Created_By, Workshop_ID, Date_Created
	from Student_2015_PB
	where Deleted = 0
	order by Created_By, Workshop_ID
</cfquery>
<cfset users = ArrayNew(1) />
<cfoutput query="exitSurveys" group="Created_By">
	<cfset user = StructNew() />
	<cfset user.user = Created_By />
	<cfset user.workshops = 0 />
	<cfset user.records = 0 />
	<cfset user.days = 1 />
	<cfset user.hours = 0 />
	<cfset user.minutes = 0 />
	<cfset thisDay = DayOfYear(Date_Created) />
	<cfset thisStartDateTime = Date_Created />
	<cfoutput group="Workshop_ID">
		<cfset user.workshops = user.workshops + 1 />
		<cfoutput>
			<cfset user.records = user.records + 1 />
			<cfif CurrentRow eq exitSurveys.RecordCount OR exitSurveys["Created_By"][currentRow + 1] neq Created_By >
				<cfset user.minutes = user.minutes + DateDiff("n", thisStartDateTime, Date_Created) />
			<cfelseif DateFormat(thisStartDateTime, 'yyyymmdd') neq DateFormat(Date_Created, 'yyyymmdd')>
				<cfset user.days = user.days + 1 />
				<cfset user.minutes = user.minutes + DateDiff("n", thisStartDateTime, Date_Created) />
				<!--- <cfset thisDay = DayOfYear(Date_Created) /> --->
				<cfset thisStartDateTime = Date_Created />
			</cfif>	
		</cfoutput>
	</cfoutput>
	<cfset user.hours = user.minutes / 60 />
	<cfset user.recordsPerHour = user.records / user.hours />
	<cfset ArrayAppend(users, user) />
</cfoutput>

<cfif IsDefined("v") and IsDefined("u")>
	<cfquery name="userExitSurveys" datasource="wms">
		select *
		from Student_2015_PB left outer join Evaluation_2015_PB
		on Evaluation_2015_PB.Student_ID = Student_2015_PB.Student_ID
		where Student_2015_PB.Deleted = 0
		and Student_2015_PB.Created_By = '#u#'
		order by Student_2015_PB.Date_Created
	</cfquery>
</cfif>

<cfset totalRecs = 0 />
<h1>Cash for College 2014-2015 Paper Based Exit Survey Data Entry</h1>

<cfoutput>
<cfif IsDefined("v") and IsDefined("u")>
	<h2>Exit Surveys Entered by #u#</h2>
	<p><a href="#script_name#">&lt;&lt;&nbsp;Back to list</a></p>
	<table border="1" cellspacing="0" cellpadding="4">
		<tr>
			<td nowrap><strong>Workshop ID</strong></td>
			<td nowrap><strong>Name</strong></td>
			<!--- <td nowrap><strong>Email</strong></td> --->
			<td nowrap><strong>DOB</strong></td>
			<td nowrap><strong>SSN</strong></td>
			<td nowrap><strong>City</strong></td>
			<td nowrap><strong>High School</strong></td>
			<td nowrap><strong>Entered By</strong></td>
			<td nowrap><strong>Entry Date</strong></td>
		</tr>
			<cfloop query="userExitSurveys">
				<tr>
					<td>#Workshop_ID#</td>
					<td>#First_Name# #Last_Name#</td>
					<!--- <td>#Email#</td> --->
					<td>#DateFormat(DOB)#</td>
					<td>#SSN#</td>
					<td>#City#</td>
					<td>#Q8#</td>
					<td>#Created_By#</td>
					<td>#DateFormat(Date_Created)# #TimeFormat(Date_Created)#</td>
				</tr>
			</cfloop>
	</table>
	<!--- <cfdump var="#userExitSurveys#"> --->
<cfelse>
	<h2>Exit Surveys Entered Summary</h2>
	<table border="1" cellspacing="0" cellpadding="4" width="400">
		<tr>
			<td nowrap><strong>Data Entry Person</strong></td>
			<td nowrap><strong>Exit Surveys Entered</strong></td>
		</tr>
			<cfloop index="i" from="1" to="#ArrayLen(users)#">
				<tr>
					<td><a href="#script_name#?v=es&u=#users[i].user#">#users[i].user#</a></td>
					<td>#users[i].records#</td>
				</tr>
				<cfset totalRecs = totalRecs + users[i].records />
			</cfloop>
			<tr>
				<td><strong>Total</strong></td>
				<td><strong>#totalRecs#</strong></td>
			</tr>
	</table>
</cfif>
</cfoutput>
